package com.fourth_groups.shopping121store.ui.home.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.fourth_groups.shopping121store.R;

public class HomeDetailsactivity extends AppCompatActivity {

    private WebView mWv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_home_detailsactivity);
        Intent intent = getIntent();
        String url = intent.getStringExtra("url");
        Log.w("+++", "跳转地址：" + url);
        mWv = (WebView) findViewById(R.id.activity_home_detailsac_webview);
        mWv.loadUrl(url);
        WebSettings settings = mWv.getSettings();
        settings.setJavaScriptEnabled(true);
        mWv.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mWv.canGoBack()) {
                mWv.goBack();//返回上一页面
                return true;
            } else {
                //System.exit(0);//退出程序
                finish();
            }
        }
        return super.onKeyDown(keyCode, event);
    }
}
